home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
F1 Licenseware
/
F1 Licenseware - Volume 1.iso
/
disks
/
049b.dms
/
049b.adf
/
MORE_SOURCE_CODE
/
Squash.AMOS
/
Squash.amosSourceCode
Wrap
AMOS Source Code
|
1992-02-26
|
3KB
|
90 lines
'=====================================================================
' Compression tutorial, By A. Smith for Amoszine
' "Compressing without PowerPacker"
'=====================================================================
' Open lowres screen to hold our image
Screen Open 0,320,256,32,Lowres
Flash Off : Curs Off
' Open screen for messages
Screen Open 1,320,30,2,Lowres
Screen Display 1,,150,,
Flash Off : Curs Off
' Load the IFF image
Screen 0
Load Iff Fsel$("","","Please select an IFF picture","")
Wait Vbl
' Pack as screen into bank 15 (what a poet!)
Screen 1 : Print "Packing picture into bank 15" : Screen 0
Spack 0 To 15
' Save memory bank to disk
Screen 1 : Print "Size of packed image ";Length(15) : Screen 0
Save Fsel$("","","Give filename for ABK image","Ensure it ends in .ABK"),15
' Squash the memory bank. Note that the function - Start - will return
' the start address of memory bank 15 and 'length' will return the length
' of the bank in bytes. The next '1' flag tells the squasher to use FAST
' compression. The 4095 will give the best compression. The 0 is the
' colour to flash when it is crunching. The value that is returned in L
' is the length of the squashed data.
Screen 1 : Print "Squashing memory bank" : Screen 0
Cls
L= Extension_5_00CE(Start(15),Length(15),1,4095,0)
' Bsave will save out the memory bank without the bank header information.
' In other words, it is just saving the bytes that were created by using
' the Squash function.
Screen 1 : Print "Size of squashed data : ";L : Screen 0
F$=Fsel$("","","Give filename for squashed data","Ensure it ends in .CMP")
Bsave F$,Start(15) To Start(15)+L
Erase 15
' Reopen the file I saved out so the length of the file can be returned.
Open In 1,F$
' Get length of file and store in SIZEOFFILE
SIZEOFFILE=Lof(1)
Close 1
' Reserve bank 15 as temporary workspace (using Fast mem), twice the
' size of the file. This is so that the decompressed data will fit
' into the memory bank.
Reserve As Work 15,SIZEOFFILE*2
' Load raw data into bank 15. Note the use of the Start function again.
' This is because we are loading in raw data which has no special ABK
' header information.
Bload F$,Start(15)
' Unsquash the raw data and store size of unsquashed data in L.
L= Extension_5_00E4(Start(15),SIZEOFFILE)
' Shrink the size of bank 15 to the size of the uncompressed data so
' we don't waste memory.
Bank Shrink 15 To L
' Redisplay the picture!
Unpack 15 To 0
Screen To Front 1
Screen 1 : Print "Saved ";L-SIZEOFFILE;" bytes!"